<template>
  <!-- 查询框 -->
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" :form="form">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="集团卡号">
              <a-input placeholder="请输入集团卡号" v-model="queryParam.groupCardNo" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" :offset="8">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="getData">查询</a-button>
              <a-button style="margin-left: 8px" @click="reset">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 表格 绑定rowkey -->
    <div style="margin-top:15px">
      <a-table :columns="columns" :dataSource="integralData" :bordered=true :pagination=false
        :rowKey="record => record.unionId" :loading="loading">
        <template slot="action" slot-scope="text, record">
          <a href="#" @click="showDeleteConfirm(record.unionId)">清除积分</a>
        </template>
      </a-table>
    </div>
  </a-card>
</template>


<script>
import { getClear, editClear } from '@/api/operateTools/index'
const columns = [{
  title: 'unionId',
  dataIndex: 'unionId'
}, {
  title: '积分',
  dataIndex: 'integral'
}, {
  title: '操作',
  dataIndex: 'state',
  scopedSlots: { customRender: 'action' }
}];

// const data = [{ }];

export default {
  data() {
    return {
      columns,
      integralData: [],
      form: this.$form.createForm(this),
      queryParam: {},
      loading: false
    }
  },
  methods: {
    // 查询数据
    getData() {
      if (!this.queryParam.groupCardNo) {
        this.$warning({
          title: '请输入集团卡号',
        });
        return;
      }
      this.loading = true
      getClear({ groupCardNo: this.queryParam.groupCardNo })
        .then(res => {
          if (res.code === 200 && res.success === true) {
            if (res.data.length == 0) {
              this.$warning({
                title: '会员不存在或会员信息存在异常',
              });
            } else {
              this.integralData = res.data
            }
          } else {
            this.$error({
              title: res.msg,
            })
          }
          this.loading = false
        })
    },
    //删除接口
    delByIds(id) {
      this.loading = true
      editClear({ unionId: id })
        .then(res => {
          if (res.code === 200 && res.success === true) {
            this.$message.success('已清除缓存积分')
            this.integralData = []
          } else {
            this.$error({
              title: res.msg,
            })
          }
          this.loading = false
        })
    },

    showDeleteConfirm(id) {
      var _this = this
      this.$confirm({
        title: '温馨提示',
        content: '确定要清除积分吗?',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          _this.delByIds(id)
          console.log(id)
        },
        onCancel() {
          console.log('Cancel');
        },
      });
    },

    // 重置
    reset() {
      this.queryParam = {}
      this.integralData = []
    }
  },
  created() {

  }
}
</script>

<style scoped>

</style>